package org.web.datajpa.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.web.datajpa.domain.Teacher;

import java.util.List;

@Repository
public interface TeacherRepository extends JpaRepository<Teacher, Long> {
    // 自定义查询：查找所有工号前四位最大值的教师
//    @Query("SELECT t FROM teacher t WHERE SUBSTRING(t.teacherId, 1, 4) = " +
//            "(SELECT MAX(SUBSTRING(t2.teacherId, 1, 4)) FROM teacher t2)")
//    List<Teacher> findTeachersWithMaxTeacherNumberPrefix();

    // 姓名模糊查询教师
    List<Teacher> findByNameContaining(String name);

    @Modifying
    @Query("DELETE FROM teacher s WHERE s.teacherId IN :ids")
    void deleteByIds(List<Integer> ids);
}
